package test.util.annotation.processor;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;

import test.exception.AnnotationException;
import test.util.annotation.Entity;

public class EntityAnnotationProcessor {

	/**
	 * Validate a class is valid.
	 * 
	 * @author YongXia.
	 * 
	 * @since jdk1.6
	 * @version 1.0
	 * 
	 * @param clazz
	 * @return If this class is not mapped to an entity, this method may be
	 *         thrown an AnnotationException, else return the table name.
	 */
	public final static String validate(final Class<? extends Serializable> clazz) {
		String tableName = null;
		Entity entity = clazz.getAnnotation(Entity.class);
		if (null != entity) {
			if (StringUtils.isNotBlank(entity.table()))
				tableName = entity.table().toUpperCase();
			else
				tableName = clazz.getSimpleName().toUpperCase();
			return tableName;
		} else
			throw new AnnotationException(clazz.getName() + " is not mapped to an entity!");
	}

	private EntityAnnotationProcessor() {
	}
}
